$(function(){
	var ap = new AjaxOperator();
    var manager = new CustomerManager();
    var thbody = $("#content");
    var customers;
    manager.findAll("findAll",findCallBack);
    function findCallBack(data){
    	customers = data;
    	manager.render(thbody, customers);
    	manager.addDeleteEvent("deleteCustomer",deleteCallBack);
    }
    function deleteCallBack(data){
    	if(data){
    		alert("delete success");
    		manager.findAll("findAll",findCallBack);
    	}
    }
  
    $("#add").on("click",function(e){
        var name = $("input[name='name']").val();
        var sex = $("input[name='sex']:checked").val();
        var salary=$("input[name='salary']").val();
        var birth = $("input[name='birth']").val();
        var customer = {name:name,sex:sex,salary:salary,birth:birth};
        manager.addCustomer("addCustomer",customer,addCallBack);
    });
    function addCallBack(data){
    	if(data){
    		alert("add success");
    		customers.push(data);
    		manager.render(thbody, customers);
    		manager.addDeleteEvent("deleteCustomer",deleteCallBack);
    		manager.addUpdateEvent("toUpdate",updateCallBack);
    	}else {
    		alert("add fail!");
    	}
    }
});